#ifndef PAGE1_WIDGET_H
#define PAGE1_WIDGET_H

#include <QWidget>
#include <QDebug>
#include <QTimer>
#include <QString>
#include <QSlider>
#include <stdio.h>
#include <string.h>
#include <QtConcurrent/QtConcurrentRun>
#include "ui_welcome_widget.h"

#include "at_cmd_parser/at_cmd_parser.h"
#include "at_cmd_parser/transparent_mode.h"
#include "nearlink_module/bearpi_h2821.h"
#include "nearlink_module/bearpi_h3863.h"
#include "DashBoardWidget.h"

class welcome_Widget;

#define CMD_LIGHT_CTRL    0xA1
#define CMD_FAN_CTRL      0xA2
#define CMD_UPLOAD_DATA   0xA3

class Page1_Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Page1_Widget(welcome_Widget *widget);
    ~Page1_Widget();

    void read_nearlink_data_thread(void);

    typedef struct device_info
    {
            unsigned char ph_value;
            unsigned char bright_state;
            unsigned char himidity;
            unsigned char temperature;
            unsigned char bright_value;
            unsigned char temp_unit_convert;
            unsigned char battery_state;
            unsigned char battery_percentage;
            unsigned char motor_ctrl;
            unsigned char light_ctrl;
    }device_info_t;

    typedef struct cmd_frame
    {
        unsigned char frame_head;
        unsigned char length;
        unsigned char cmd;
        unsigned char payload[66];    //最后两个字节是CRC
    }cmd_frame_t;

    device_info_t device_info;
    device_info_t device_info_old;
signals:

public slots:

private slots:
    void updatetimer_timeout_handler();

    void on_pb_clear_rx_data_clicked();

    void on_pb_light_on_clicked();
    void on_pb_light_off_clicked();
    void on_pb_fan_on_clicked();
    void on_pb_fan_off_clicked();

private:
    welcome_Widget *welcomewidget;
    Ui::welcome_Widget *welcome_ui;
    QTimer *update_timer;
    bool update_flag;
    bearpi_h3863 *nearlink_module;
    DashBoardWidget *dashBoardWidget;

    void rx_data_display(QString str);
    void iot_kit_data_process(unsigned char *p_data, int len);
    void display_light_state(unsigned char state);
    void display_fan_state(unsigned char state);
};


#endif

